#!/bin/bash

PRJ=$1
CLSPATH=$2
MAIN=$3
ARGS=$4
HOST=$5
SEED=$6

echo "project  = $PRJ"
echo "classpath = $CLSPATH"
echo "main = $MAIN"
echo "args = $ARGS"
echo "host = $HOST"
echo "seed = $SEED"

echo "Preparing directory..."
ssh -x $HOST "rm -rf /tmp/$SEED" > /dev/null
ssh -x $HOST "mkdir /tmp/$SEED" > /dev/null
echo "done."

echo "Copying project..."
cd $PRJ
tar cvzf "/tmp/$SEED".tgz . > /dev/null
scp  "/tmp/$SEED".tgz "$HOST:/tmp/$SEED/." > /dev/null
echo "done."

echo "Running..."
ssh -x "$HOST" "cd /tmp/$SEED/;tar xvzf /tmp/$SEED.tgz" > /dev/null
ssh -x "$HOST" "cd /tmp/$SEED/; java -cp $CLSPATH $MAIN $ARGS" &
echo "done."



